package com.gcit.seniorWish.web.modular.system.service.impl;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.gcit.seniorWish.web.common.persistence.dao.DictMapper;
import com.gcit.seniorWish.web.common.persistence.dao.MenuMapper;
import com.gcit.seniorWish.web.common.persistence.dao.RoleMenuMapper;
import com.gcit.seniorWish.web.common.persistence.model.Dict;
import com.gcit.seniorWish.web.common.persistence.model.Menu;
import com.gcit.seniorWish.web.modular.system.dao.MenuDao;
import com.gcit.seniorWish.web.modular.system.service.IMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单服务
 *
 * @author fengshuonan
 * @date 2017-05-05 22:20
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {


	@Resource
	private RoleMenuMapper roleMenuMapper;

	@Override
	@Transactional
	public void delMenu(String menuId) {
		//删除菜单
		this.baseMapper.deleteById(menuId);
		//删除关联的relation
		roleMenuMapper.delete(Condition.create().eq("menu_id", menuId));
	}

	@Override
	@Transactional
	public void delMenuContainSubMenus(String menuId) {
		Menu menu = this.baseMapper.selectById(menuId);
		//删除当前菜单
		delMenu(menuId);
		//删除所有子菜单
		this.baseMapper.delete(Condition.create().like("pids", "[" + menu.getId() + "]"));
	}
}
